package com.airbat.prize.modules.tool.dal.mysql.codegen;

import com.airbat.prize.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import com.airbat.prize.mybits.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

@Mapper
public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> {

//    default List<ToolSchemaTableDO> selectList(Collection<String> tableSchemas, String tableName, String tableComment) {
//        return selectList(new QueryWrapperX<ToolSchemaTableDO>().in("table_schema", tableSchemas)
//                .likeIfPresent("table_name", tableName)
//                .likeIfPresent("table_comment", tableComment));
//    }

//    default ToolSchemaTableDO selectByTableSchemaAndTableName(String tableSchema, String tableName) {
//        return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema",tableSchema)
//                .eq("table_name", tableName));
//    }

    @Select("SELECT 'DS' AS Table_Schema, utc.TABLE_NAME, ut.LAST_ANALYZED AS Create_Time, utc.COMMENTS AS TABLE_COMMENT \n" +
            "FROM user_tables ut INNER JOIN user_tab_comments utc ON ut.TABLE_NAME = utc.TABLE_NAME \n" +
            "WHERE utc.TABLE_NAME LIKE '%'||#{tableName}||'%' AND utc.COMMENTS LIKE '%'||#{tableComment}||'%'")
    List<ToolSchemaTableDO> selectList(@Param("tableSchemas") Collection<String> tableSchemas, @Param("tableName") String tableName, @Param("tableComment") String tableComment);

    @Select("SELECT 'DS' Table_Schema, utc.TABLE_NAME, ut.LAST_ANALYZED AS Create_Time, utc.COMMENTS AS TABLE_COMMENT \n" +
            "FROM user_tables ut INNER JOIN user_tab_comments utc ON ut.TABLE_NAME = utc.TABLE_NAME \n" +
            "WHERE utc.TABLE_NAME = #{tableName}")
    ToolSchemaTableDO selectByTableSchemaAndTableName(@Param("tableName") String tableName);

}
